Fix missing Microsoft.Extensions.Configuration using in generated ClientSettings when BindCore is customized - #10905
Conversation
… using is emitted Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
jorgerangel-msft
left a comment
There was a problem hiding this comment.
@copilot ensure we add a unit test that uses TestData to move the BindCore method do custom code and then validate that the generated code is generated as expected
…ore customized Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
…ore is customized Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Done in 9b9... — |
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
commit: |
…entSettings when BindCore is customized (microsoft#10905) When a generated `ClientSettings` type's `BindCore(IConfigurationSection)` is moved to custom code, the generated partial still references `IConfigurationSection` in its XML doc summary, but `using Microsoft.Extensions.Configuration;` was dropped — so the generated code no longer compiles. **Root cause:** Namespace imports are registered from actual type references during writing. The class description used a plain string `<see cref="IConfigurationSection"/>` rather than a real type reference, so it never registered the namespace. The only thing registering `Microsoft.Extensions.Configuration` was the generated `BindCore` parameter type — once `BindCore` is customized away and filtered out, nothing registers it. ### Changes - **`ClientSettingsProvider.BuildDescription`**: reference the actual types via the `:C` cref formatter (matching the `ClientOptionsProvider` convention) instead of hardcoded `<see cref>` strings. This registers the `Microsoft.Extensions.Configuration` namespace while rendering an identical cref, so normal generated output is unchanged. ```csharp // before => $"Represents the settings used to configure a <see cref=\"{_clientProvider.Name}\"/> that can be loaded from an <see cref=\"IConfigurationSection\"/>."; // after => $"Represents the settings used to configure a {_clientProvider.Type:C} that can be loaded from an {IConfigurationSectionType:C}."; ``` - **Regression test** (`TestGeneratedSettings_WithCustomizedBindCore`) + TestData: uses TestData to move `BindCore` into a custom partial, asserts it is no longer generated, and validates the full generated output against an expected snapshot file (`TestData/ClientSettingsProviderTests/TestGeneratedSettings_WithCustomizedBindCore.cs`), confirming the `using` is still emitted. Fails without the fix. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
When a generated
ClientSettingstype'sBindCore(IConfigurationSection)is moved to custom code, the generated partial still referencesIConfigurationSectionin its XML doc summary, butusing Microsoft.Extensions.Configuration;was dropped — so the generated code no longer compiles.Root cause: Namespace imports are registered from actual type references during writing. The class description used a plain string
<see cref="IConfigurationSection"/>rather than a real type reference, so it never registered the namespace. The only thing registeringMicrosoft.Extensions.Configurationwas the generatedBindCoreparameter type — onceBindCoreis customized away and filtered out, nothing registers it.Changes
ClientSettingsProvider.BuildDescription: reference the actual types via the:Ccref formatter (matching theClientOptionsProviderconvention) instead of hardcoded<see cref>strings. This registers theMicrosoft.Extensions.Configurationnamespace while rendering an identical cref, so normal generated output is unchanged.TestGeneratedSettings_WithCustomizedBindCore) + TestData: uses TestData to moveBindCoreinto a custom partial, asserts it is no longer generated, and validates the full generated output against an expected snapshot file (TestData/ClientSettingsProviderTests/TestGeneratedSettings_WithCustomizedBindCore.cs), confirming theusingis still emitted. Fails without the fix.